package cn.epet.dao.implement.database;

import java.util.List;

import cn.epet.dao.IPetStoreDao;
import cn.epet.model.entity_class.PetStore;

public class PetStoreDaoMysqlImpl extends BaseDao implements IPetStoreDao {
	@Override
	public List<PetStore> getAllPetStores() {
		String query="SELECT * FROM `epet`.`petstore` ORDER BY `ID` ASC  LIMIT 0,50;";
		try {
			@SuppressWarnings("unchecked")
			List<PetStore> stores=super.queryForBean(query, PetStore.class);
		return stores;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	@Override
	public int updatePetStore(PetStore s) throws Exception {
		String updateSql="update `epet`.`petstore` set `NAME`='"+s.getNAME()+"',`PASSWORD`='"+s.getPASSWORD()+"',`BALANCE`="+s.getBALANCE()+" where `ID`="+s.getID()+";";
		int num=super.update(updateSql);
		return num;
		}
	@Override
	public PetStore findStoreByName(String name){
		String query="SELECT * FROM `epet`.`petstore` WHERE NAME ='"+name+"'";
		try {
			@SuppressWarnings("unchecked")
			List<PetStore> stores=super.queryForBean(query, PetStore.class);
			if(stores.size()>0){
				return stores.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	@Override
	public PetStore findStoreByID(int id){
		String query="SELECT * FROM `epet`.`petstore` WHERE ID ='"+id+"'";
		try {
			@SuppressWarnings("unchecked")
			List<PetStore> stores=super.queryForBean(query, PetStore.class);
			if(stores.size()>0){
				return stores.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		
		}
		return null;
	}
}
